package chatting.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;


/**
 * 왜 분리했는가?
 * 
 * 서버로부터 input, 화면에 output
 * run()
 * 1. i/o 작업 - 
 * 	input : 서버
 * 	output : 화면 (표준출력 - system.out.println()
 * 2. 연결닫기 (I/O, Socket)
 * 
 * 
 * 
 * 
 * ClientThread 에서는 어떤 기능을 구현 했는가?
 * - ClientThread.java - run()메소드로 구현
 * - 서버에서 읽어서 화면(command창)에 출력
 * - Input Stream : Server로부터 input(Socket.getInputStream())
 * - outPut Stream : 화면으로 output(system.out.println())
 */
public class ClientThread implements Runnable{
	
	private Socket socket;
	
	public ClientThread(Socket socket){
		this.socket = socket;
	}
	
	public void run(){
		
		BufferedReader br = null;
	
		
		try{
			br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		
			String str = br.readLine();
			while(str != null){
				System.out.println(str);
				str = br.readLine();
			}
		}catch (IOException e){
			e.printStackTrace();
		}finally{
			if(br != null)
				try {
					br.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
	}
	
}
